/**
  * AntRanking Copyright (c) 2008-2012 INRIA, University of Lille 1
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
  * version 2 of the License, or (at your option) any later version.
  *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  * 
  * Contact: 
  * 	benjamin.bertein@gmail.com,
  * 	nacim.hamdad@gmail.com
  * 	nicolas.haderer@inria.fr
  *
  * Author: Nacim Hamdad,Benjamin Bertein, Haderer Nicolas
  */
package com.google.antranking.adapter;


import android.content.Context;
import android.graphics.Color;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class AntRankingGridAdapter extends BaseAdapter {

	private Context mContext;
	
	private Integer[] icones;
	
	private String[] iconesNames;
	
	public AntRankingGridAdapter(Context ctx, Integer[] icones, String[] iconesNames){
		this.mContext = ctx;
		
		this.icones = icones;
		this.iconesNames = iconesNames;
		
	}
	
	
	public int getCount() {return iconesNames.length;}
	
	public Object getItem(int arg0) {return null;}
	
	public long getItemId(int arg0) {return 0;}

	@Override
	public View getView(int index, View convertView, ViewGroup arg2) {
		
		
		LinearLayout view = null;
		
		if (convertView == null) {  
			
            view = new LinearLayout(mContext);
			view.setOrientation(LinearLayout.VERTICAL);
			
			final ImageView img = new ImageView(mContext);
            img.setLayoutParams(new GridView.LayoutParams(130, 72));
            img.setScaleType(ImageView.ScaleType.CENTER_CROP);
            img.setPadding(8, 8, 8, 8);
            img.setImageResource(icones[index]);
            
            final TextView text = new TextView(mContext);
            text.setText(iconesNames[index]);
            text.setGravity(Gravity.CENTER_HORIZONTAL); 
            text.setTextColor(Color.BLACK);
            
            view.setGravity(Gravity.CENTER_HORIZONTAL); 
            view.setTag(iconesNames[index]);
            view.addView(img);
            view.addView(text);
            
		}
		else 
			view = (LinearLayout) convertView;
        
		return view;
	}

	
}
